clear
set more off
cd ""	//Set your directory here
use "Latin America data"
set seed 6451166

	*Run your models here (Table 1)
		meoprobit pork c.dm2##i.closed personalism || groupindicator:	
		meoprobit pork c.dm2##i.closed personalism female leftright government coalition  federalism clientelism seniority  || groupindicator:		
		
	*Now make a pretty figure (Figure 1)
		meoprobit pork c.dm2##i.closed personalism || groupindicator:	
	
	
	*set up variables that we will use during the loops
		gen pred1 = .
		gen pred2 = .
		gen pred3 = .
		gen pred4 = .
		gen pred5 = .

		capture drop xvalue
		gen xvalue = . 

		local a = 1	
		
		*get predictions
				
				local a = 0.69314718			//dm = 2 to make the figure for multimember districts only. 
				local b = 1
				
				while `a' <= 4.2484952 {
				
				replace pred1 = normprob(_b[/cut1] - (_b[dm2]*`a' + _b[personalism]*5)) in `b'
				replace pred2 = (normprob(_b[/cut2] - (_b[dm2]*`a' + _b[personalism]*5))) - (normprob(_b[/cut1] - (_b[dm2]*`a' + _b[personalism]*5))) in `b'
				replace pred3 = (normprob(_b[/cut3] - (_b[dm2]*`a' + _b[personalism]*5))) - (normprob(_b[/cut2] - (_b[dm2]*`a' + _b[personalism]*5))) in `b'
				replace pred4 = 1-(normprob(_b[/cut3] - (_b[dm2]*`a' + _b[personalism]*5))) in `b'					
				replace xvalue = `a' in `b'
				local a = `a' + 0.01				
				local b = `b' + 1			
				}		
					
					
			*Get cumultative predicted probabilities 	
				replace pred2 = pred1 + pred2
				replace pred3 = pred2 + pred3
				replace pred4 = pred3 + pred4
			
			*de-log dm
				replace xvalue = exp(xvalue) 
			
			*gen figure
				twoway (area pred1 xvalue,  lcolor(black)) (rarea pred1 pred2 xvalue,  lcolor(black)) (rarea pred2 pred3 xvalue,  lcolor(black)) (rarea pred3 pred4 xvalue,  lcolor(black)), legend(order(1 "Not at all important" 2 "A little important" 3 "Fairly important" 4 "Very important")) name(tempg1, replace) graphregion(color(white)) ytitle("Cumulative probability") xlabel(0(10)70) ylab(0(0.2)1, nogrid) xtitle("District magnitude") 
		